#import <QuartzCore/QuartzCore.h>
#import "common.h"

void loadImage(UIImageView *image, NSString *url) {
    //[image sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:img_placehold];
}

UIColor *getUIColor(int rgbValue) {
    return [UIColor
            colorWithRed:(CGFloat) ((((rgbValue & 0xFF0000) >> 16)) / 255.0)
                   green:(CGFloat) (((CGFloat) ((rgbValue & 0x00FF00) >> 8)) / 255.0)
                    blue:(CGFloat) (((CGFloat) (rgbValue & 0x0000FF)) / 255.0)
                   alpha:1.0];
}
CGSize getTextSize(NSString *string,CGFloat width, UIFont *font) {
    CGSize sizeText = [string boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : font}context:nil].size;
    return sizeText;
}

CALayer *getLine(int X,int toX,int Y,int toY,UIColor *color){
    CAShapeLayer *lineShape = nil;
    CGMutablePathRef linePath = nil;
    linePath = CGPathCreateMutable();
    lineShape = [CAShapeLayer layer];
    lineShape.lineWidth = 0.5f;
    lineShape.lineCap = kCALineCapRound;
    lineShape.strokeColor = color.CGColor;
    CGPathMoveToPoint(linePath, NULL, X, Y);
    CGPathAddLineToPoint(linePath, NULL, toX, toY);
    lineShape.path = linePath;
    CGPathRelease(linePath);
    return lineShape;
}

NSString *getDeviceToken(NSData *data)
{
    NSString *string=[[[[data description] stringByReplacingOccurrencesOfString: @"<" withString: @""]
                       stringByReplacingOccurrencesOfString: @">" withString: @""]
                      stringByReplacingOccurrencesOfString: @" " withString: @""];
    return string;
}

UIColor *colorFromHexCode(NSString *hexString)
{
    NSString *cleanString = [hexString stringByReplacingOccurrencesOfString:@"#" withString:@""];
    if([cleanString length] == 3) {
        cleanString = [NSString stringWithFormat:@"%@%@%@%@%@%@",
                       [cleanString substringWithRange:NSMakeRange(0, 1)],[cleanString substringWithRange:NSMakeRange(0, 1)],
                       [cleanString substringWithRange:NSMakeRange(1, 1)],[cleanString substringWithRange:NSMakeRange(1, 1)],
                       [cleanString substringWithRange:NSMakeRange(2, 1)],[cleanString substringWithRange:NSMakeRange(2, 1)]];
    }
    if([cleanString length] == 6) {
        cleanString = [cleanString stringByAppendingString:@"ff"];
    }
    
    unsigned int baseValue;
    [[NSScanner scannerWithString:cleanString] scanHexInt:&baseValue];
    
    float red = ((baseValue >> 24) & 0xFF)/255.0f;
    float green = ((baseValue >> 16) & 0xFF)/255.0f;
    float blue = ((baseValue >> 8) & 0xFF)/255.0f;
    float alpha = ((baseValue >> 0) & 0xFF)/255.0f;
    
    return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
}



